package com.jike.noobmoney.adapter;


import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.jike.noobmoney.R;
import com.jike.noobmoney.contants.ConstantValue;
import com.jike.noobmoney.entity.SubmitOrderDetailEntity;
import com.jike.noobmoney.entity.TaskDetailEntity;

import java.util.ArrayList;

import me.iwf.photopicker.PhotoPreview;

/**
 * 我的任务 提交详情
 * */
public class TaskDetailUnAdapter extends BaseRecyclerAdapter<SubmitOrderDetailEntity.OrderinfoBean.TaskstepBean> {


    private Context context;

    public onImageClickListener onImageClickListener;

    public interface onImageClickListener {
        void onImageClick(int position);
    }

    public TaskDetailUnAdapter(Context context,onImageClickListener onImageClickListener) {
        super(R.layout.item_task_detail_un);
        this.context = context;
        this.onImageClickListener = onImageClickListener;
    }

    @Override
    protected void onBindViewHolder(SmartViewHolder holder, SubmitOrderDetailEntity.OrderinfoBean.TaskstepBean item, int position) {
        holder.text(R.id.tv_step_title, item.getText());
        ImageView ivStepImage = (ImageView) holder.findViewById(R.id.iv_step_image);
        Glide.with(context).load(ConstantValue.IMG_BASEURL_MARK + item.getPicture()).into(ivStepImage);

        ImageView iv_pic = (ImageView) holder.findViewById(R.id.iv_pic);
        if ("1".equals(item.getFlag())){
            iv_pic.setVisibility(View.VISIBLE);
        }else if ("0".equals(item.getFlag())){
            iv_pic.setVisibility(View.GONE);
        }


        if (!TextUtils.isEmpty(item.getTj_url())) {
            Glide.with(context).load(ConstantValue.IMG_BASEURL_TJ + item.getTj_url()).into(iv_pic);
        }


        ivStepImage.setOnClickListener(v -> {
            String url = ConstantValue.IMG_BASEURL_MARK + item.getPicture();
            ArrayList<String> photoPaths = new ArrayList<>();
            photoPaths.add(url);
            PhotoPreview.builder()
                    .setPhotos(photoPaths)
                    .setCurrentItem(position)
                    .setShowDeleteButton(true)
                    .start((Activity) context);
        });

        iv_pic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onImageClickListener != null) {
                    onImageClickListener.onImageClick(position);
                }
            }
        });
    }
}
